import { defineStore } from "pinia";
import { ref } from "vue";
import type { FriendChatType } from "@/types/friendChatType.ts";

export const useFriendChatStore = defineStore("friend", () => {
  // 后端数据
  const _friendChatList = [
    {
      id: 1,
      imgUrl: "/public/images/1.png",
      tip: 2,
      name: "风继续吹",
      time: "7/23 23:22",
      news: "你好，最近怎么样？",
    },
    {
      id: 2,
      imgUrl: "/public/images/2.png",
      tip: 33,
      name: "陈奕迅",
      time: "7/23 15:32",
      news: "记得今晚一起吃晚饭。",
    },
    {
      id: 3,
      imgUrl: "/public/images/3.png",
      tip: 66,
      name: "周杰伦",
      time: "7/23 10:52",
      news: "我在机场了，你那边情况如何？",
    },
    {
      id: 4,
      imgUrl: "/public/images/4.png",
      tip: 43,
      name: "张国荣",
      time: "7/21 09:22",
      news: "关于明天的会议，你准备好了吗？",
    },
    {
      id: 5,
      imgUrl: "/public/images/5.png",
      tip: 43,
      name: "陈慧娴",
      time: "7/28 03:22",
      news: "关于明天的会议，你准备好了吗？",
    },
    {
      id: 6,
      imgUrl: "/public/images/6.png",
      tip: 43,
      name: "张学友",
      time: "7/13 22:22",
      news: "关于明天的会议，你准备好了吗？",
    },
    {
      id: 7,
      imgUrl: "/public/images/7.png",
      tip: 43,
      name: "杨千嬅",
      time: "7/25 14:22",
      news: "关于明天的会议，你准备好了吗？",
    },
    {
      id: 8,
      imgUrl: "/public/images/8.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
    {
      id: 9,
      imgUrl: "/public/images/9.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
    {
      id: 10,
      imgUrl: "/public/images/10.png",
      tip: 53,
      name: "周兴哲",
      time: "7/16 10:34",
      news: "项目进展顺利，猛猛学。",
    },
    {
      id: 11,
      imgUrl: "/public/images/11.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
    {
      id: 12,
      imgUrl: "/public/images/12.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
    {
      id: 13,
      imgUrl: "/public/images/13.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
    {
      id: 14,
      imgUrl: "/public/images/1.png",
      tip: 2,
      name: "风继续吹",
      time: "7/23 23:22",
      news: "你好，最近怎么样？",
    },
    {
      id: 15,
      imgUrl: "/public/images/2.png",
      tip: 33,
      name: "陈奕迅",
      time: "7/23 15:32",
      news: "记得今晚一起吃晚饭。",
    },
    {
      id: 16,
      imgUrl: "/public/images/3.png",
      tip: 66,
      name: "周杰伦",
      time: "7/23 10:52",
      news: "我在机场了，你那边情况如何？",
    },
    {
      id: 17,
      imgUrl: "/public/images/4.png",
      tip: 43,
      name: "张国荣",
      time: "7/21 09:22",
      news: "关于明天的会议，你准备好了吗？",
    },
    {
      id: 18,
      imgUrl: "/public/images/5.png",
      tip: 43,
      name: "陈慧娴",
      time: "7/28 03:22",
      news: "关于明天的会议，你准备好了吗？",
    },
    {
      id: 19,
      imgUrl: "/public/images/6.png",
      tip: 43,
      name: "张学友",
      time: "7/13 22:22",
      news: "关于明天的会议，你准备好了吗？",
    },
    {
      id: 20,
      imgUrl: "/public/images/7.png",
      tip: 43,
      name: "杨千嬅",
      time: "7/25 14:22",
      news: "关于明天的会议，你准备好了吗？",
    },
    {
      id: 21,
      imgUrl: "/public/images/8.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
    {
      id: 22,
      imgUrl: "/public/images/9.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
    {
      id: 23,
      imgUrl: "/public/images/10.png",
      tip: 53,
      name: "周兴哲",
      time: "7/16 10:34",
      news: "项目进展顺利，猛猛学。",
    },
    {
      id: 24,
      imgUrl: "/public/images/11.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
    {
      id: 25,
      imgUrl: "/public/images/12.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
    {
      id: 26,
      imgUrl: "/public/images/13.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
    {
      id: 27,
      imgUrl: "/public/images/1.png",
      tip: 2,
      name: "风继续吹",
      time: "7/23 23:22",
      news: "你好，最近怎么样？",
    },
    {
      id: 28,
      imgUrl: "/public/images/2.png",
      tip: 33,
      name: "陈奕迅",
      time: "7/23 15:32",
      news: "记得今晚一起吃晚饭。",
    },
    {
      id: 29,
      imgUrl: "/public/images/3.png",
      tip: 66,
      name: "周杰伦",
      time: "7/23 10:52",
      news: "我在机场了，你那边情况如何？",
    },
    {
      id: 30,
      imgUrl: "/public/images/4.png",
      tip: 43,
      name: "张国荣",
      time: "7/21 09:22",
      news: "关于明天的会议，你准备好了吗？",
    },
    {
      id: 31,
      imgUrl: "/public/images/5.png",
      tip: 43,
      name: "陈慧娴",
      time: "7/28 03:22",
      news: "关于明天的会议，你准备好了吗？",
    },
    {
      id: 32,
      imgUrl: "/public/images/6.png",
      tip: 43,
      name: "张学友",
      time: "7/13 22:22",
      news: "关于明天的会议，你准备好了吗？",
    },
    {
      id: 33,
      imgUrl: "/public/images/7.png",
      tip: 43,
      name: "杨千嬅",
      time: "7/25 14:22",
      news: "关于明天的会议，你准备好了吗？",
    },
    {
      id: 34,
      imgUrl: "/public/images/8.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
    {
      id: 35,
      imgUrl: "/public/images/9.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
    {
      id: 36,
      imgUrl: "/public/images/10.png",
      tip: 53,
      name: "周兴哲",
      time: "7/16 10:34",
      news: "项目进展顺利，猛猛学。",
    },
    {
      id: 37,
      imgUrl: "/public/images/11.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
    {
      id: 38,
      imgUrl: "/public/images/12.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
    {
      id: 39,
      imgUrl: "/public/images/13.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
    {
      id: 40,
      imgUrl: "/public/images/11.png",
      tip: 43,
      name: "林俊杰",
      time: "7/16 10:34",
      news: "项目进展顺利，感谢你的努力。",
    },
  ];

  // 前端数据
  const friendChatList = ref<FriendChatType[]>([]);

  // 模拟异步请求
  const getFriendChatList = (page: number, size: number) => {
    return new Promise<{
      data: FriendChatType[];
      page: number;
      total: number;
      hasMore: boolean;
    }>((resolve) => {
      setTimeout(() => {
        const data = _friendChatList.slice((page - 1) * size, page * size);
        friendChatList.value = [...friendChatList.value, ...data];
        resolve({
          data,
          page,
          total: _friendChatList.length,
          hasMore: page * size < _friendChatList.length,
        });
      }, 100);
    });
  };

  return {
    friendChatList,
    getFriendChatList,
  };
});
